package com.ikas.ai.server.module.morningpaper.model.elements.wholeyear;

import com.ikas.ai.server.module.morningpaper.consts.MorningPaperConditionWholeYearVariableNames;
import com.ikas.ai.server.module.morningpaper.exception.MorningPaperException;
import com.ikas.ai.server.module.morningpaper.model.dto.MorningPaperVariablesDto;
import com.ikas.ai.server.module.morningpaper.model.elements.MorningPaperTopElement;

public abstract class AbstractElementMachineConditionWholeYearCount extends MorningPaperTopElement {
    protected Long fillWholeYearCount(AbstractElementMachineConditionWholeYearCount element, MorningPaperVariablesDto mv){
        Long valueFromTable = getValueFromVariableTable(element, Long.class);
        try {
            if (MorningPaperConditionWholeYearVariableNames.conditionGInWholeYearCount.name().equals(element.getMorningPaperVariableName())){
                valueFromTable += mv.getMachineU01ConditionGPowerUpCount();
                valueFromTable += mv.getMachineU02ConditionGPowerUpCount();
                valueFromTable += mv.getMachineU03ConditionGPowerUpCount();
                valueFromTable += mv.getMachineU04ConditionGPowerUpCount();
            }
            if (MorningPaperConditionWholeYearVariableNames.conditionPInWholeYearCount.name().equals(element.getMorningPaperVariableName())){
                valueFromTable += mv.getMachineU01ConditionPPowerUpCount();
                valueFromTable += mv.getMachineU02ConditionPPowerUpCount();
                valueFromTable += mv.getMachineU03ConditionPPowerUpCount();
                valueFromTable += mv.getMachineU04ConditionPPowerUpCount();
            }
            if (MorningPaperConditionWholeYearVariableNames.conditionPCInWholeYearCount.name().equals(element.getMorningPaperVariableName())){
                valueFromTable += mv.getMachineU01ConditionPCPowerUpCount();
                valueFromTable += mv.getMachineU02ConditionPCPowerUpCount();
                valueFromTable += mv.getMachineU03ConditionPCPowerUpCount();
                valueFromTable += mv.getMachineU04ConditionPCPowerUpCount();
            }
            return valueFromTable;
        } catch (NullPointerException e) {
            throw new MorningPaperException(String.format(MorningPaperException.needsFieldIsEmpty,mv.toString()));
        }
    }
}
